/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package day02;

public class TienDien {

 /*
  * Tinh tien dien
  */   
    public double tinhTienDien(int csc, int csm){
        double tiendien = 0;
        int sd = csm - csc;
        
        if(sd <=100){
          tiendien = (sd * 550)*1.1;         
        }
        else 
            if(sd<=150){
               tiendien = (100 * 550 + (sd - 100)*1110) *1.1;
            }
            else 
                if(sd <=200){
                tiendien = (100 *550 + 50*1110 + (sd - 150)*1470)*1.1;                
                }
                else 
                    if(sd <=300){
                    tiendien= (100*550 + 50*1110+50 *1470 + (sd - 200)*1600)*1.1;
                                    
                    }
                    else   
                        if(sd <=400){
                         tiendien = (100*550 + 50*1110 + 50* 1470 + 100*1600 + (sd - 300)*1720)*1.1;                        
                        }
                        else {
                        tiendien = (100*550 + 50*1110 + 50*1470 + 100*1600 + 100*1720 + (sd - 400)*1780)*1.1;
                        
                        }
        return tiendien;
        
    }
/*
 * Kiem tra so nguyen to
 */
 public boolean kientraSNT(int n){        
        boolean result = true;
        if(n == 2 || n == 3){
            result = true;
        }
        else {
             for(int i = 2; i<=Math.sqrt(n);i++){
                 if(n % i == 0){
                     result =  false;                 
                     break;
                 }
             }
        }           
    return result;
}
/*
 * Tim UCLN
 */
public int ucln(int a, int b){
    for(int i = a<b?a:b;i>=1;i--){
        if( a% i == 0 && b % i == 0){
           return i;
        }
    }    
    return 0;
}

/*
 * In ra các số nguyên tố
 */
public void printSNT(int n){
 if(n == 2 || n == 3){
     System.out.println("So Nguyen to =" +n); 
 }
 else
 {
   for(int i =4; i<=n;i++){
     if(this.kientraSNT(i)){
         System.out.println("So Nguyen to = " + i);         
     }
   
   }
  
 
 }
     


}

/*
 * in so dao nguoc
 * Nhap vao n 123 --> 321 
 */
public String reserse(int n){
  String acc="";
  int temp;
  do{
      temp = n %10;
      acc+=temp; 
  } 
  while((n/= 10) >0);  
  return acc.trim();
  
    
}

    
    
    
    
}
